<?php

namespace DesignModel;

/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-19
 * Time: 18:52
 * @description:策略模式demo 依赖倒置 控制反转
 * @Author: yfl
 * @QQ 554665488
 */
use DesignModel\strategy\FemaleUserStrategy;
use DesignModel\strategy\maleUserStrategy;
use DesignModel\strategy\UserStrategy;

define('BASEDIR', __DIR__ . '/..');


require_once __DIR__ . '/Loader.php';
spl_autoload_register("\\DesignModel\\Loader::autoload");

class strategyTest
{
    //策略对象
    protected $strategy;

    public function index()
    {
        echo '=广告'. $this->strategy->showAd().PHP_EOL;
        echo '=分类'. $this->strategy->showGateway().PHP_EOL;
    }

    public function setStrategy(UserStrategy $userStrategy)
    {
        $this->strategy = $userStrategy;
    }
}

$index = new strategyTest();
$_GET['type'] = 'male';
if ($_GET['type'] == 'female') {
    $strategy = new FemaleUserStrategy();
} else if ($_GET['type'] == 'male') {
    $strategy = new MaleUserStrategy();
}
if(isset($strategy)){
    $index->setStrategy($strategy);
    $index->index();
}